<?php
class Plantes extends CI_Controller{
	
	public function index($test){
		
		print_r($test);
		echo $test;
	}
	
	public function gestion(){
		
		require_once "ajax.php";
		$ajax = ajax();
		
		$query=$this->doctrine->em->createQuery("SELECT p FROM Plante p ORDER BY p.nom");
		$plantes=$query->getResult();
		
		foreach ($plantes AS $plante){
			$id=$plante->getId();
			$ajax->click("ck".$id,$ajax->test=$ajax->call("Plantes/index"));
		}
		
		$this->load->view('vGestionPlantes',array('plantes'=>$plantes,'dataAjax'=>$ajax));
	}
	
	public function nom($nom){
		require_once(APPPATH.'controllers/Menu.php');
		$menu=new Menu();
		
		$this->load->view('vHeader');
		$menu->index();
		$nomPlante=str_replace("-", " ", $nom);
		
		$query=$this->doctrine->em->createQuery("SELECT p FROM Plante p WHERE p.nom='".$nomPlante."'");
		$plantes=$query->getResult();
		
		foreach ($plantes AS $plante){
			$infosPlante=array(
					"id"=>$plante->getId(),
					"nom"=>$plante->getNom(),
					"datePlantation"=>$plante->getDatePlantation(),
					"floraison"=>$plante->getFloraison(),
					"exposition"=>$plante->getExposition(),
					"arosage"=>$plante->getArosage(),
					"feuillage"=>$plante->getFeuillage(),
					"utilisation"=>$plante->getUtilisation(),
					"multiplication"=>$plante->getMultiplication(),
					"embranchement"=>$plante->getIdEmbranchement()->getNom(),
					"sousEmbranchement"=>$plante->getIdSousEmbranchement()->getNom(),
					"classe"=>$plante->getIdClasse()->getNom(),
					"espece"=>$plante->getIdEspece()->getNom(),
					"groupe"=>$plante->getIdGroupe()->getNom(),
					"genre"=>$plante->getIdGenre()->getNom(),
					"famille"=>$plante->getIdFamille()->getNom(),
			);
		}
		
		$this->load->view('vPlante',array('plantes'=>$plantes,'nomPlante'=>$nomPlante,'infosPlante'=>$infosPlante));
		$this->load->view('vFooter');
	}
}